//
//  DiseasesCell.m
//  Food
//
//  Created by dllo on 15/7/19.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DiseasesCell.h"
#import "UIImageView+WebCache.h"
@implementation DiseasesCell

- (void)dealloc
{
    [_img release];
    [_name release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.img = [[[UIImageView alloc] init] autorelease];
//        self.img.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:self.img];
        self.name = [[[UILabel alloc] init] autorelease];
//        self.name.backgroundColor = [UIColor orangeColor];
        self.name.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.name];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    self.img.frame = CGRectMake(0, 0, layoutAttributes.size.width, layoutAttributes.size.height - 20);
    self.name.frame = CGRectMake(0, self.img.frame.size.height, layoutAttributes.size.width, 20);
}

- (void)setFoodCases:(DiseaseFoodCases *)foodCases
{
    if (_foodCases != foodCases) {
        [_foodCases release];
        _foodCases = [foodCases retain];
    }
    
    self.name.text = foodCases.name;
    [self.img sd_setImageWithURL:[NSURL URLWithString:foodCases.imagePathThumbnails]];
}
@end
